package com.hot100;

public class Solution234 {
    public boolean isPalindrome(ListNode head) {
        if (head == null || head.next == null) return true;
        ListNode slow = head;
        ListNode fast = head.next;
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
        }
        ListNode cur = slow.next;
        ListNode pre = null;
        fast = cur.next;
        while (fast != null) {
            cur.next = pre;
            pre = cur;
            cur = fast;
            fast = fast.next;
        }
        cur.next = pre;
        while (cur != null) {
            if (cur.val != head.val) return false;
            cur = cur.next;
            head = head.next;
        }
        return true;
    }
}
